package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.InsertException;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.exception.sql.UpdateException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.SpecTypeMapper;
import com.fantastic.model.pojo.zjs.SpecType;
import com.fantastic.service.zjs.SpecTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/30 18:30
 * @description:
 */
@Service
public class SpecTypeServiceImpl implements SpecTypeService {

    @Resource
    private SpecTypeMapper specTypeMapper;

    /**
     * 查询
     * 无条件时是查询全部的分页查询
     * 有条件时是查询条件的分页查询
     *
     * @param specType
     * @return
     */
    @Override
    public List<SpecType> listSpecType(SpecType specType) {
        List<SpecType> specTypes = specTypeMapper.listSpecType(specType);
        IsEmptyUtils.listIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), specTypes);
        return specTypes;
    }

    /**
     * 查询单个菜品规格类型
     *
     * @param specTypeId 菜品规格类型id
     * @return
     */
    @Override
    public SpecType getSpecType(Integer specTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), specTypeId);
        return specTypeMapper.getSpecType(specTypeId);
    }

    /**
     * 添加菜品规格类型信息
     *
     * @param specType 菜品规格类型对象
     * @return
     */
    @Override
    public Integer insertSpecType(SpecType specType) {
        IsEmptyUtils.stringIsEmpty(new InsertException(RespStatusInfo.DATA_ERROR), specType.getSpecTypeName());
        //为null表示使用默认
        if (specType.getSpecTypeCount() == null) {
            specType.setSpecTypeCount(0);
        }
        return specTypeMapper.insertSpecType(specType);
    }

    /**
     * 修改菜品规格类型信息
     *
     * @param specType
     * @return
     */
    @Override
    public Integer updateSpecType(SpecType specType) {
        IsEmptyUtils.integerIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR), specType.getSpecTypeId());
        return specTypeMapper.updateSpecType(specType);
    }

    /**
     * 删除菜品规格类型信息
     *
     * @param specTypeId
     * @return
     */
    @Override
    public Integer deleteSpecType(Integer specTypeId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), specTypeId);
        return specTypeMapper.deleteSpecType(specTypeId);
    }
}
